package com.toulouseculture;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.toulouseculture.bo.CulturePlace;
import com.toulouseculture.bo.LibraryPlace;
import com.toulouseculture.controller.CulturePlaceAdapter;
import com.toulouseculture.controller.CulturePlaceController;

public class LibraryListActivity extends ListActivity {

	// private static final int MENU_HELP = Menu.FIRST;
	//
	// private static final int DIALOG_HELP = 0;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.librarylist);

		CulturePlaceController facade = CulturePlaceController.getInstance();

		facade.populateLibrary(getResources().openRawResource(R.raw.library));

		List<LibraryPlace> libraries = facade.getAllLibraryPlace();

		CulturePlaceAdapter adapter = new CulturePlaceAdapter(libraries, this);

		setListAdapter(adapter);

		// button
		Button compassButton = (Button) findViewById(R.id.alllibraryCompassButton);
		compassButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(LibraryListActivity.this, CulturePlaceMapsActivity.class);
				i.putExtra(CulturePlaceController.CULTURE_PLACE_ID, new Long(CulturePlace.LIBRARY_ID));
				startActivity(i);
			}
		});

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent i = new Intent(this, LibraryActivity.class);
		i.putExtra(CulturePlaceController.CULTURE_PLACE_ID, id);
		startActivity(i);

	}

	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	// super.onCreateOptionsMenu(menu);
	// menu.add(0, MENU_HELP, 0, R.string.Help);
	// MenuItem item = menu.getItem(0);
	// item.setIcon(android.R.drawable.ic_menu_info_details);
	// return true;
	// }
	//
	// @Override
	// public boolean onMenuItemSelected(int featureId, MenuItem item) {
	// switch (item.getItemId()) {
	// case MENU_HELP:
	// showDialog(DIALOG_HELP);
	// }
	//
	// return super.onMenuItemSelected(featureId, item);
	// }
	//
	// @Override
	// protected Dialog onCreateDialog(int id) {
	// Dialog dialog;
	// switch (id) {
	// case DIALOG_HELP:
	// dialog = new Dialog(this);
	//
	// // dialog.setContentView(android.R.layout);
	// dialog.setTitle(R.string.Help);
	// TextView tv = new TextView(this);
	// tv.setPadding(5, 0, 0, 5);
	// tv.setText(R.string.HelpFavoriContent);
	// dialog.setContentView(tv);
	//
	// break;
	// default:
	// dialog = null;
	// }
	// return dialog;
	// }

}